import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'dart:async';

class DateTimeDemo extends StatefulWidget {
  DateTimeDemo({Key key}) : super(key: key);

  _DateTimeDemoState createState() => _DateTimeDemoState();
}

class _DateTimeDemoState extends State<DateTimeDemo> {
  DateTime _selectdateTime = DateTime.now();
  TimeOfDay selectedTime = TimeOfDay(
    hour: 9,
    minute: 55,
  );
  Future _selectDate() async {
    final DateTime thisdate = await showDatePicker(
      context: context,
      initialDate: _selectdateTime,
      firstDate: DateTime(1900),
      lastDate: DateTime(2101),
    );
    if (thisdate == null) return;
    setState(() {
      _selectdateTime = thisdate;
    });
  }

  Future _selecttime() async {
    final TimeOfDay thistime =
        await showTimePicker(context: context, initialTime: selectedTime);
    if (thistime == null) return;
    setState(() {
      selectedTime = thistime;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DateTimeDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                InkWell(
                  onTap: _selectDate,
                  child: Row(
                    children: <Widget>[
                      Text(DateFormat.yMMMd().format(_selectdateTime)),
                      Icon(
                        Icons.arrow_drop_down,
                      )
                    ],
                  ),
                ),
                InkWell(
                  onTap: _selecttime,
                  child: Row(
                    children: <Widget>[
                      Text(selectedTime.format(context)),
                      Icon(
                        Icons.arrow_drop_down,
                      )
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
